{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "ee0835d6",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>编号</th>\n",
       "      <th>数量</th>\n",
       "      <th>产品名</th>\n",
       "      <th>是否自产</th>\n",
       "      <th>样品数量</th>\n",
       "      <th>样品良好率</th>\n",
       "      <th>价格</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>100001000.0</td>\n",
       "      <td>104.0</td>\n",
       "      <td>沙发</td>\n",
       "      <td>Y</td>\n",
       "      <td>3</td>\n",
       "      <td>1</td>\n",
       "      <td>1000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>100002000.0</td>\n",
       "      <td>197.0</td>\n",
       "      <td>椅子</td>\n",
       "      <td>N</td>\n",
       "      <td>3</td>\n",
       "      <td>1.5</td>\n",
       "      <td>--</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>100003000.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>床头柜</td>\n",
       "      <td>N</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1</td>\n",
       "      <td>850</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>100004000.0</td>\n",
       "      <td>201.0</td>\n",
       "      <td>电脑</td>\n",
       "      <td>12</td>\n",
       "      <td>1</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2700</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>NaN</td>\n",
       "      <td>203.0</td>\n",
       "      <td>电视</td>\n",
       "      <td>Y</td>\n",
       "      <td>3</td>\n",
       "      <td>2</td>\n",
       "      <td>3600</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>100006000.0</td>\n",
       "      <td>207.0</td>\n",
       "      <td>洗衣机</td>\n",
       "      <td>Y</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1</td>\n",
       "      <td>800</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>100007000.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>电冰箱</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2</td>\n",
       "      <td>HURLEY</td>\n",
       "      <td>950</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>100008000.0</td>\n",
       "      <td>213.0</td>\n",
       "      <td>书柜</td>\n",
       "      <td>Y</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>100009000.0</td>\n",
       "      <td>215.0</td>\n",
       "      <td>大衣柜</td>\n",
       "      <td>Y</td>\n",
       "      <td>na</td>\n",
       "      <td>2</td>\n",
       "      <td>1800</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "            编号     数量  产品名 是否自产 样品数量   样品良好率    价格\n",
       "0  100001000.0  104.0   沙发    Y    3       1  1000\n",
       "1  100002000.0  197.0   椅子    N    3     1.5    --\n",
       "2  100003000.0    NaN  床头柜    N  NaN       1   850\n",
       "3  100004000.0  201.0   电脑   12    1     NaN  2700\n",
       "4          NaN  203.0   电视    Y    3       2  3600\n",
       "5  100006000.0  207.0  洗衣机    Y  NaN       1   800\n",
       "6  100007000.0    NaN  电冰箱  NaN    2  HURLEY   950\n",
       "7  100008000.0  213.0   书柜    Y    1       1   NaN\n",
       "8  100009000.0  215.0  大衣柜    Y   na       2  1800"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import pandas as pd\n",
    "mydf1 = pd.read_excel('mybook1.xls',sheet_name=0)\n",
    "mydf1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "99c868d9",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>编号</th>\n",
       "      <th>数量</th>\n",
       "      <th>产品名</th>\n",
       "      <th>是否自产</th>\n",
       "      <th>样品数量</th>\n",
       "      <th>样品良好率</th>\n",
       "      <th>价格</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>100001000.0</td>\n",
       "      <td>104.0</td>\n",
       "      <td>沙发</td>\n",
       "      <td>Y</td>\n",
       "      <td>3.0</td>\n",
       "      <td>1</td>\n",
       "      <td>1000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>100002000.0</td>\n",
       "      <td>197.0</td>\n",
       "      <td>椅子</td>\n",
       "      <td>N</td>\n",
       "      <td>3.0</td>\n",
       "      <td>1.5</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>100003000.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>床头柜</td>\n",
       "      <td>N</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1</td>\n",
       "      <td>850.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>100004000.0</td>\n",
       "      <td>201.0</td>\n",
       "      <td>电脑</td>\n",
       "      <td>12</td>\n",
       "      <td>1.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2700.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>NaN</td>\n",
       "      <td>203.0</td>\n",
       "      <td>电视</td>\n",
       "      <td>Y</td>\n",
       "      <td>3.0</td>\n",
       "      <td>2</td>\n",
       "      <td>3600.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>100006000.0</td>\n",
       "      <td>207.0</td>\n",
       "      <td>洗衣机</td>\n",
       "      <td>Y</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1</td>\n",
       "      <td>800.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>100007000.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>电冰箱</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2.0</td>\n",
       "      <td>HURLEY</td>\n",
       "      <td>950.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>100008000.0</td>\n",
       "      <td>213.0</td>\n",
       "      <td>书柜</td>\n",
       "      <td>Y</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>100009000.0</td>\n",
       "      <td>215.0</td>\n",
       "      <td>大衣柜</td>\n",
       "      <td>Y</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2</td>\n",
       "      <td>1800.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "            编号     数量  产品名 是否自产  样品数量   样品良好率      价格\n",
       "0  100001000.0  104.0   沙发    Y   3.0       1  1000.0\n",
       "1  100002000.0  197.0   椅子    N   3.0     1.5     NaN\n",
       "2  100003000.0    NaN  床头柜    N   NaN       1   850.0\n",
       "3  100004000.0  201.0   电脑   12   1.0     NaN  2700.0\n",
       "4          NaN  203.0   电视    Y   3.0       2  3600.0\n",
       "5  100006000.0  207.0  洗衣机    Y   NaN       1   800.0\n",
       "6  100007000.0    NaN  电冰箱  NaN   2.0  HURLEY   950.0\n",
       "7  100008000.0  213.0   书柜    Y   1.0       1     NaN\n",
       "8  100009000.0  215.0  大衣柜    Y   NaN       2  1800.0"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import pandas as pd\n",
    "missing_values = [\"n/a\",\"na\",\"--\"]\n",
    "mydf1 = pd.read_excel('mybook1.xls',sheet_name=0,na_values=missing_values)\n",
    "mydf1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "fc22f410",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>编号</th>\n",
       "      <th>数量</th>\n",
       "      <th>产品名</th>\n",
       "      <th>是否自产</th>\n",
       "      <th>样品数量</th>\n",
       "      <th>样品良好率</th>\n",
       "      <th>价格</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>100001000.0</td>\n",
       "      <td>104.0</td>\n",
       "      <td>沙发</td>\n",
       "      <td>Y</td>\n",
       "      <td>3.0</td>\n",
       "      <td>1</td>\n",
       "      <td>1000.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "            编号     数量 产品名 是否自产  样品数量 样品良好率      价格\n",
       "0  100001000.0  104.0  沙发    Y   3.0     1  1000.0"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "mydf2 = mydf1.dropna(inplace=True)\n",
    "mydf1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "9c6719f9",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>编号</th>\n",
       "      <th>数量</th>\n",
       "      <th>产品名</th>\n",
       "      <th>是否自产</th>\n",
       "      <th>样品数量</th>\n",
       "      <th>样品良好率</th>\n",
       "      <th>价格</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>100001000.0</td>\n",
       "      <td>104.0</td>\n",
       "      <td>沙发</td>\n",
       "      <td>Y</td>\n",
       "      <td>3.0</td>\n",
       "      <td>1</td>\n",
       "      <td>1000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>100002000.0</td>\n",
       "      <td>197.0</td>\n",
       "      <td>椅子</td>\n",
       "      <td>N</td>\n",
       "      <td>3.0</td>\n",
       "      <td>1.5</td>\n",
       "      <td>18.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>100003000.0</td>\n",
       "      <td>18.0</td>\n",
       "      <td>床头柜</td>\n",
       "      <td>N</td>\n",
       "      <td>18.0</td>\n",
       "      <td>1</td>\n",
       "      <td>850.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>100004000.0</td>\n",
       "      <td>201.0</td>\n",
       "      <td>电脑</td>\n",
       "      <td>12</td>\n",
       "      <td>1.0</td>\n",
       "      <td>18</td>\n",
       "      <td>2700.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>18.0</td>\n",
       "      <td>203.0</td>\n",
       "      <td>电视</td>\n",
       "      <td>Y</td>\n",
       "      <td>3.0</td>\n",
       "      <td>2</td>\n",
       "      <td>3600.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>100006000.0</td>\n",
       "      <td>207.0</td>\n",
       "      <td>洗衣机</td>\n",
       "      <td>Y</td>\n",
       "      <td>18.0</td>\n",
       "      <td>1</td>\n",
       "      <td>800.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>100007000.0</td>\n",
       "      <td>18.0</td>\n",
       "      <td>电冰箱</td>\n",
       "      <td>18</td>\n",
       "      <td>2.0</td>\n",
       "      <td>HURLEY</td>\n",
       "      <td>950.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>100008000.0</td>\n",
       "      <td>213.0</td>\n",
       "      <td>书柜</td>\n",
       "      <td>Y</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1</td>\n",
       "      <td>18.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>100009000.0</td>\n",
       "      <td>215.0</td>\n",
       "      <td>大衣柜</td>\n",
       "      <td>Y</td>\n",
       "      <td>18.0</td>\n",
       "      <td>2</td>\n",
       "      <td>1800.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "            编号     数量  产品名 是否自产  样品数量   样品良好率      价格\n",
       "0  100001000.0  104.0   沙发    Y   3.0       1  1000.0\n",
       "1  100002000.0  197.0   椅子    N   3.0     1.5    18.0\n",
       "2  100003000.0   18.0  床头柜    N  18.0       1   850.0\n",
       "3  100004000.0  201.0   电脑   12   1.0      18  2700.0\n",
       "4         18.0  203.0   电视    Y   3.0       2  3600.0\n",
       "5  100006000.0  207.0  洗衣机    Y  18.0       1   800.0\n",
       "6  100007000.0   18.0  电冰箱   18   2.0  HURLEY   950.0\n",
       "7  100008000.0  213.0   书柜    Y   1.0       1    18.0\n",
       "8  100009000.0  215.0  大衣柜    Y  18.0       2  1800.0"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "mydf3 = mydf1.fillna(18)\n",
    "mydf3"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "e11635de",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0    100001000.0\n",
       "1    100002000.0\n",
       "2    100003000.0\n",
       "3    100004000.0\n",
       "4    100008000.0\n",
       "5    100006000.0\n",
       "6    100007000.0\n",
       "7    100008000.0\n",
       "8    100009000.0\n",
       "Name: 编号, dtype: float64"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "mydf4 = mydf1['编号'].fillna(100008000.0)\n",
    "mydf4"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "id": "1fe13aba",
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "C:\\Users\\18027\\AppData\\Local\\Temp\\ipykernel_2856\\3202088426.py:6: FutureWarning: errors='ignore' is deprecated and will raise in a future version. Use to_datetime without passing `errors` and catch exceptions explicitly instead\n",
      "  mydf['日期'] = pd.to_datetime(mydf['日期'], errors='ignore')\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>日期</th>\n",
       "      <th>水果名</th>\n",
       "      <th>价格</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2021/6/01</td>\n",
       "      <td>香蕉</td>\n",
       "      <td>3.5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2021/6/02</td>\n",
       "      <td>苹果</td>\n",
       "      <td>6.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>20210603</td>\n",
       "      <td>挑子</td>\n",
       "      <td>4.5</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "          日期 水果名   价格\n",
       "0  2021/6/01  香蕉  3.5\n",
       "1  2021/6/02  苹果  6.0\n",
       "2   20210603  挑子  4.5"
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import pandas as pd\n",
    "data={\"日期\":['2021/6/01','2021/6/02','20210603'],\n",
    "     \"水果名\":['香蕉','苹果','挑子'],\n",
    "     \"价格\":[3.5,6,4.5]}\n",
    "mydf = pd.DataFrame(data)\n",
    "mydf['日期'] = pd.to_datetime(mydf['日期'], errors='ignore')\n",
    "mydf"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "id": "e79660ce",
   "metadata": {},
   "outputs": [
    {
     "ename": "ValueError",
     "evalue": "time data \"2021/6/01\" doesn't match format \"%Y%m%d\", at position 0. You might want to try:\n    - passing `format` if your strings have a consistent format;\n    - passing `format='ISO8601'` if your strings are all ISO8601 but not necessarily in exactly the same format;\n    - passing `format='mixed'`, and the format will be inferred for each element individually. You might want to use `dayfirst` alongside this.",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mValueError\u001b[0m                                Traceback (most recent call last)",
      "Cell \u001b[1;32mIn[29], line 2\u001b[0m\n\u001b[0;32m      1\u001b[0m \u001b[38;5;28;01mimport\u001b[39;00m \u001b[38;5;21;01mpandas\u001b[39;00m \u001b[38;5;28;01mas\u001b[39;00m \u001b[38;5;21;01mpd\u001b[39;00m\n\u001b[1;32m----> 2\u001b[0m mydf[\u001b[38;5;124m'\u001b[39m\u001b[38;5;124m日期\u001b[39m\u001b[38;5;124m'\u001b[39m] \u001b[38;5;241m=\u001b[39m \u001b[43mpd\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mto_datetime\u001b[49m\u001b[43m(\u001b[49m\u001b[43mmydf\u001b[49m\u001b[43m[\u001b[49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43m日期\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[43m]\u001b[49m\u001b[43m,\u001b[49m\u001b[38;5;28;43mformat\u001b[39;49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43m%\u001b[39;49m\u001b[38;5;124;43mY\u001b[39;49m\u001b[38;5;124;43m%\u001b[39;49m\u001b[38;5;124;43mm\u001b[39;49m\u001b[38;5;132;43;01m%d\u001b[39;49;00m\u001b[38;5;124;43m'\u001b[39;49m\u001b[43m)\u001b[49m\n\u001b[0;32m      3\u001b[0m mydf\n",
      "File \u001b[1;32m~\\AppData\\Local\\Programs\\Python\\Python312\\Lib\\site-packages\\pandas\\core\\tools\\datetimes.py:1067\u001b[0m, in \u001b[0;36mto_datetime\u001b[1;34m(arg, errors, dayfirst, yearfirst, utc, format, exact, unit, infer_datetime_format, origin, cache)\u001b[0m\n\u001b[0;32m   1065\u001b[0m         result \u001b[38;5;241m=\u001b[39m arg\u001b[38;5;241m.\u001b[39mmap(cache_array)\n\u001b[0;32m   1066\u001b[0m     \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[1;32m-> 1067\u001b[0m         values \u001b[38;5;241m=\u001b[39m \u001b[43mconvert_listlike\u001b[49m\u001b[43m(\u001b[49m\u001b[43marg\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_values\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;28;43mformat\u001b[39;49m\u001b[43m)\u001b[49m\n\u001b[0;32m   1068\u001b[0m         result \u001b[38;5;241m=\u001b[39m arg\u001b[38;5;241m.\u001b[39m_constructor(values, index\u001b[38;5;241m=\u001b[39marg\u001b[38;5;241m.\u001b[39mindex, name\u001b[38;5;241m=\u001b[39marg\u001b[38;5;241m.\u001b[39mname)\n\u001b[0;32m   1069\u001b[0m \u001b[38;5;28;01melif\u001b[39;00m \u001b[38;5;28misinstance\u001b[39m(arg, (ABCDataFrame, abc\u001b[38;5;241m.\u001b[39mMutableMapping)):\n",
      "File \u001b[1;32m~\\AppData\\Local\\Programs\\Python\\Python312\\Lib\\site-packages\\pandas\\core\\tools\\datetimes.py:433\u001b[0m, in \u001b[0;36m_convert_listlike_datetimes\u001b[1;34m(arg, format, name, utc, unit, errors, dayfirst, yearfirst, exact)\u001b[0m\n\u001b[0;32m    431\u001b[0m \u001b[38;5;66;03m# `format` could be inferred, or user didn't ask for mixed-format parsing.\u001b[39;00m\n\u001b[0;32m    432\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28mformat\u001b[39m \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m \u001b[38;5;129;01mand\u001b[39;00m \u001b[38;5;28mformat\u001b[39m \u001b[38;5;241m!=\u001b[39m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mmixed\u001b[39m\u001b[38;5;124m\"\u001b[39m:\n\u001b[1;32m--> 433\u001b[0m     \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[43m_array_strptime_with_fallback\u001b[49m\u001b[43m(\u001b[49m\u001b[43marg\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mname\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mutc\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;28;43mformat\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mexact\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43merrors\u001b[49m\u001b[43m)\u001b[49m\n\u001b[0;32m    435\u001b[0m result, tz_parsed \u001b[38;5;241m=\u001b[39m objects_to_datetime64(\n\u001b[0;32m    436\u001b[0m     arg,\n\u001b[0;32m    437\u001b[0m     dayfirst\u001b[38;5;241m=\u001b[39mdayfirst,\n\u001b[1;32m   (...)\u001b[0m\n\u001b[0;32m    441\u001b[0m     allow_object\u001b[38;5;241m=\u001b[39m\u001b[38;5;28;01mTrue\u001b[39;00m,\n\u001b[0;32m    442\u001b[0m )\n\u001b[0;32m    444\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m tz_parsed \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m:\n\u001b[0;32m    445\u001b[0m     \u001b[38;5;66;03m# We can take a shortcut since the datetime64 numpy array\u001b[39;00m\n\u001b[0;32m    446\u001b[0m     \u001b[38;5;66;03m# is in UTC\u001b[39;00m\n",
      "File \u001b[1;32m~\\AppData\\Local\\Programs\\Python\\Python312\\Lib\\site-packages\\pandas\\core\\tools\\datetimes.py:467\u001b[0m, in \u001b[0;36m_array_strptime_with_fallback\u001b[1;34m(arg, name, utc, fmt, exact, errors)\u001b[0m\n\u001b[0;32m    456\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21m_array_strptime_with_fallback\u001b[39m(\n\u001b[0;32m    457\u001b[0m     arg,\n\u001b[0;32m    458\u001b[0m     name,\n\u001b[1;32m   (...)\u001b[0m\n\u001b[0;32m    462\u001b[0m     errors: \u001b[38;5;28mstr\u001b[39m,\n\u001b[0;32m    463\u001b[0m ) \u001b[38;5;241m-\u001b[39m\u001b[38;5;241m>\u001b[39m Index:\n\u001b[0;32m    464\u001b[0m \u001b[38;5;250m    \u001b[39m\u001b[38;5;124;03m\"\"\"\u001b[39;00m\n\u001b[0;32m    465\u001b[0m \u001b[38;5;124;03m    Call array_strptime, with fallback behavior depending on 'errors'.\u001b[39;00m\n\u001b[0;32m    466\u001b[0m \u001b[38;5;124;03m    \"\"\"\u001b[39;00m\n\u001b[1;32m--> 467\u001b[0m     result, tz_out \u001b[38;5;241m=\u001b[39m \u001b[43marray_strptime\u001b[49m\u001b[43m(\u001b[49m\u001b[43marg\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mfmt\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mexact\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mexact\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43merrors\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43merrors\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mutc\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mutc\u001b[49m\u001b[43m)\u001b[49m\n\u001b[0;32m    468\u001b[0m     \u001b[38;5;28;01mif\u001b[39;00m tz_out \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m:\n\u001b[0;32m    469\u001b[0m         unit \u001b[38;5;241m=\u001b[39m np\u001b[38;5;241m.\u001b[39mdatetime_data(result\u001b[38;5;241m.\u001b[39mdtype)[\u001b[38;5;241m0\u001b[39m]\n",
      "File \u001b[1;32mstrptime.pyx:501\u001b[0m, in \u001b[0;36mpandas._libs.tslibs.strptime.array_strptime\u001b[1;34m()\u001b[0m\n",
      "File \u001b[1;32mstrptime.pyx:451\u001b[0m, in \u001b[0;36mpandas._libs.tslibs.strptime.array_strptime\u001b[1;34m()\u001b[0m\n",
      "File \u001b[1;32mstrptime.pyx:583\u001b[0m, in \u001b[0;36mpandas._libs.tslibs.strptime._parse_with_format\u001b[1;34m()\u001b[0m\n",
      "\u001b[1;31mValueError\u001b[0m: time data \"2021/6/01\" doesn't match format \"%Y%m%d\", at position 0. You might want to try:\n    - passing `format` if your strings have a consistent format;\n    - passing `format='ISO8601'` if your strings are all ISO8601 but not necessarily in exactly the same format;\n    - passing `format='mixed'`, and the format will be inferred for each element individually. You might want to use `dayfirst` alongside this."
     ]
    }
   ],
   "source": [
    "import pandas as pd\n",
    "mydf['日期'] = pd.to_datetime(mydf['日期'],format='%Y%m%d')\n",
    "mydf"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "6a04a306",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>姓名</th>\n",
       "      <th>性别</th>\n",
       "      <th>年龄</th>\n",
       "      <th>成绩</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>李明</td>\n",
       "      <td>男</td>\n",
       "      <td>14</td>\n",
       "      <td>115</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>张亮</td>\n",
       "      <td>男</td>\n",
       "      <td>113</td>\n",
       "      <td>89</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>周可佳</td>\n",
       "      <td>女</td>\n",
       "      <td>15</td>\n",
       "      <td>98</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>王瑞</td>\n",
       "      <td>女</td>\n",
       "      <td>104</td>\n",
       "      <td>135</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>刘伦瑞</td>\n",
       "      <td>男</td>\n",
       "      <td>112</td>\n",
       "      <td>94</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    姓名 性别   年龄   成绩\n",
       "0   李明  男   14  115\n",
       "1   张亮  男  113   89\n",
       "2  周可佳  女   15   98\n",
       "3   王瑞  女  104  135\n",
       "4  刘伦瑞  男  112   94"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import pandas as pd\n",
    "data={\n",
    "    \"姓名\":['李明','张亮','周可佳','王瑞','刘伦瑞'],\n",
    "    \"性别\":['男','男','女','女','男'],\n",
    "    \"年龄\":[14,113,15,104,112],\n",
    "    \"成绩\":[115,89,98,135,94]\n",
    "}\n",
    "mydf1 = pd.DataFrame(data)\n",
    "mydf1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "67595b26",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>姓名</th>\n",
       "      <th>性别</th>\n",
       "      <th>年龄</th>\n",
       "      <th>成绩</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>李明</td>\n",
       "      <td>男</td>\n",
       "      <td>14</td>\n",
       "      <td>115</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>张亮</td>\n",
       "      <td>男</td>\n",
       "      <td>15</td>\n",
       "      <td>89</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>周可佳</td>\n",
       "      <td>女</td>\n",
       "      <td>15</td>\n",
       "      <td>98</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>王瑞</td>\n",
       "      <td>女</td>\n",
       "      <td>104</td>\n",
       "      <td>135</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>刘伦瑞</td>\n",
       "      <td>男</td>\n",
       "      <td>112</td>\n",
       "      <td>94</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    姓名 性别   年龄   成绩\n",
       "0   李明  男   14  115\n",
       "1   张亮  男   15   89\n",
       "2  周可佳  女   15   98\n",
       "3   王瑞  女  104  135\n",
       "4  刘伦瑞  男  112   94"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "mydf1.loc[1,'年龄'] = 15\n",
    "mydf1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "a23148ab",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>姓名</th>\n",
       "      <th>性别</th>\n",
       "      <th>年龄</th>\n",
       "      <th>成绩</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>李明</td>\n",
       "      <td>男</td>\n",
       "      <td>14</td>\n",
       "      <td>115</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>张亮</td>\n",
       "      <td>男</td>\n",
       "      <td>15</td>\n",
       "      <td>89</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>周可佳</td>\n",
       "      <td>女</td>\n",
       "      <td>15</td>\n",
       "      <td>98</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>王瑞</td>\n",
       "      <td>女</td>\n",
       "      <td>16</td>\n",
       "      <td>135</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>刘伦瑞</td>\n",
       "      <td>男</td>\n",
       "      <td>16</td>\n",
       "      <td>94</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    姓名 性别  年龄   成绩\n",
       "0   李明  男  14  115\n",
       "1   张亮  男  15   89\n",
       "2  周可佳  女  15   98\n",
       "3   王瑞  女  16  135\n",
       "4  刘伦瑞  男  16   94"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "for x in mydf1.index:\n",
    "    if mydf1.loc[x,'年龄'] >100:\n",
    "        mydf1.loc[x,'年龄'] = 16\n",
    "mydf1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "014f57ae",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>姓名</th>\n",
       "      <th>性别</th>\n",
       "      <th>年龄</th>\n",
       "      <th>成绩</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>张亮</td>\n",
       "      <td>男</td>\n",
       "      <td>15</td>\n",
       "      <td>89</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>周可佳</td>\n",
       "      <td>女</td>\n",
       "      <td>15</td>\n",
       "      <td>98</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>刘伦瑞</td>\n",
       "      <td>男</td>\n",
       "      <td>16</td>\n",
       "      <td>94</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    姓名 性别  年龄  成绩\n",
       "1   张亮  男  15  89\n",
       "2  周可佳  女  15  98\n",
       "4  刘伦瑞  男  16  94"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "for x in mydf1.index:\n",
    "    if mydf1.loc[x,'成绩'] >100:\n",
    "        mydf1.drop(x)\n",
    "mydf1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "adb6a1db",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>姓名</th>\n",
       "      <th>性别</th>\n",
       "      <th>年龄</th>\n",
       "      <th>成绩</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>张亮</td>\n",
       "      <td>男</td>\n",
       "      <td>15</td>\n",
       "      <td>89</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>周可佳</td>\n",
       "      <td>女</td>\n",
       "      <td>15</td>\n",
       "      <td>98</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>刘伦瑞</td>\n",
       "      <td>男</td>\n",
       "      <td>16</td>\n",
       "      <td>94</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    姓名 性别  年龄  成绩\n",
       "1   张亮  男  15  89\n",
       "2  周可佳  女  15  98\n",
       "4  刘伦瑞  男  16  94"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "mydf1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "bab33aac",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>姓名</th>\n",
       "      <th>性别</th>\n",
       "      <th>年龄</th>\n",
       "      <th>成绩</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>李明</td>\n",
       "      <td>男</td>\n",
       "      <td>14</td>\n",
       "      <td>95</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>张亮</td>\n",
       "      <td>男</td>\n",
       "      <td>13</td>\n",
       "      <td>89</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>周可佳</td>\n",
       "      <td>女</td>\n",
       "      <td>15</td>\n",
       "      <td>98</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>王瑞</td>\n",
       "      <td>女</td>\n",
       "      <td>14</td>\n",
       "      <td>35</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>刘伦瑞</td>\n",
       "      <td>男</td>\n",
       "      <td>12</td>\n",
       "      <td>94</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>王瑞</td>\n",
       "      <td>女</td>\n",
       "      <td>14</td>\n",
       "      <td>35</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>刘伦瑞</td>\n",
       "      <td>男</td>\n",
       "      <td>12</td>\n",
       "      <td>94</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    姓名 性别  年龄  成绩\n",
       "0   李明  男  14  95\n",
       "1   张亮  男  13  89\n",
       "2  周可佳  女  15  98\n",
       "3   王瑞  女  14  35\n",
       "4  刘伦瑞  男  12  94\n",
       "5   王瑞  女  14  35\n",
       "6  刘伦瑞  男  12  94"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 删除重复的数据\n",
    "import pandas as pd\n",
    "data={\n",
    "    \"姓名\":['李明','张亮','周可佳','王瑞','刘伦瑞','王瑞','刘伦瑞'],\n",
    "    \"性别\":['男','男','女','女','男','女','男'],\n",
    "    \"年龄\":[14,13,15,14,12,14,12],\n",
    "    \"成绩\":[95,89,98,35,94,35,94]\n",
    "}\n",
    "mydf1 = pd.DataFrame(data)\n",
    "mydf1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "c7ede0a4",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0    False\n",
       "1    False\n",
       "2    False\n",
       "3    False\n",
       "4    False\n",
       "5     True\n",
       "6     True\n",
       "dtype: bool"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "mydf1.duplicated()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "5c3b5e99",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>姓名</th>\n",
       "      <th>性别</th>\n",
       "      <th>年龄</th>\n",
       "      <th>成绩</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>李明</td>\n",
       "      <td>男</td>\n",
       "      <td>14</td>\n",
       "      <td>95</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>张亮</td>\n",
       "      <td>男</td>\n",
       "      <td>13</td>\n",
       "      <td>89</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>周可佳</td>\n",
       "      <td>女</td>\n",
       "      <td>15</td>\n",
       "      <td>98</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>王瑞</td>\n",
       "      <td>女</td>\n",
       "      <td>14</td>\n",
       "      <td>35</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>刘伦瑞</td>\n",
       "      <td>男</td>\n",
       "      <td>12</td>\n",
       "      <td>94</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    姓名 性别  年龄  成绩\n",
       "0   李明  男  14  95\n",
       "1   张亮  男  13  89\n",
       "2  周可佳  女  15  98\n",
       "3   王瑞  女  14  35\n",
       "4  刘伦瑞  男  12  94"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "mydf1.drop_duplicates(inplace=True)\n",
    "mydf1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "c1381d63",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>A</th>\n",
       "      <th>B</th>\n",
       "      <th>C</th>\n",
       "      <th>D</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>赵可佳</td>\n",
       "      <td>女</td>\n",
       "      <td>25</td>\n",
       "      <td>5869.32</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>张可</td>\n",
       "      <td>男</td>\n",
       "      <td>28</td>\n",
       "      <td>7256.34</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>周远</td>\n",
       "      <td>女</td>\n",
       "      <td>21</td>\n",
       "      <td>6895.89</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>徐南</td>\n",
       "      <td>男</td>\n",
       "      <td>30</td>\n",
       "      <td>7289.72</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "     A  B   C        D\n",
       "0  赵可佳  女  25  5869.32\n",
       "1   张可  男  28  7256.34\n",
       "2   周远  女  21  6895.89\n",
       "3   徐南  男  30  7289.72"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import pandas as pd\n",
    "data={\"A\":[\"赵可佳\",\"张可\",\"周远\",\"徐南\"],\n",
    "    \"B\":['女','男','女','男'],\n",
    "    \"C\":[25,28,21,30],\n",
    "    \"D\":[5869.32,7256.34,6895.89,7289.72]}\n",
    "mydf1 = pd.DataFrame(data)\n",
    "mydf1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "id": "336d49b9",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>姓名</th>\n",
       "      <th>性别</th>\n",
       "      <th>年龄</th>\n",
       "      <th>工资</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>赵可佳</td>\n",
       "      <td>女</td>\n",
       "      <td>25</td>\n",
       "      <td>5869.32</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>张可</td>\n",
       "      <td>男</td>\n",
       "      <td>28</td>\n",
       "      <td>7256.34</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>周远</td>\n",
       "      <td>女</td>\n",
       "      <td>21</td>\n",
       "      <td>6895.89</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>徐南</td>\n",
       "      <td>男</td>\n",
       "      <td>30</td>\n",
       "      <td>7289.72</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    姓名 性别  年龄       工资\n",
       "0  赵可佳  女  25  5869.32\n",
       "1   张可  男  28  7256.34\n",
       "2   周远  女  21  6895.89\n",
       "3   徐南  男  30  7289.72"
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "mydf1.columns = ['姓名','性别','年龄','工资']\n",
    "mydf1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "id": "090710a5",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>职工姓名</th>\n",
       "      <th>性别</th>\n",
       "      <th>年龄</th>\n",
       "      <th>工资</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>王丽</td>\n",
       "      <td>女</td>\n",
       "      <td>25</td>\n",
       "      <td>5869.32</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>张可</td>\n",
       "      <td>男</td>\n",
       "      <td>28</td>\n",
       "      <td>7256.34</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>周远</td>\n",
       "      <td>女</td>\n",
       "      <td>21</td>\n",
       "      <td>6895.89</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>徐南</td>\n",
       "      <td>男</td>\n",
       "      <td>30</td>\n",
       "      <td>7289.72</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "  职工姓名 性别  年龄       工资\n",
       "0   王丽  女  25  5869.32\n",
       "1   张可  男  28  7256.34\n",
       "2   周远  女  21  6895.89\n",
       "3   徐南  男  30  7289.72"
      ]
     },
     "execution_count": 32,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "mydf1.rename(columns={'姓名':'职工姓名'},inplace=True)\n",
    "mydf1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "id": "32d5341c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>姓名</th>\n",
       "      <th>性别</th>\n",
       "      <th>年龄</th>\n",
       "      <th>工资</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>王丽</td>\n",
       "      <td>女</td>\n",
       "      <td>25</td>\n",
       "      <td>5869.32</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>张可</td>\n",
       "      <td>男</td>\n",
       "      <td>28</td>\n",
       "      <td>7256.34</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>周远</td>\n",
       "      <td>女</td>\n",
       "      <td>21</td>\n",
       "      <td>6895.89</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>徐南</td>\n",
       "      <td>男</td>\n",
       "      <td>30</td>\n",
       "      <td>7289.72</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   姓名 性别  年龄       工资\n",
       "0  王丽  女  25  5869.32\n",
       "1  张可  男  28  7256.34\n",
       "2  周远  女  21  6895.89\n",
       "3  徐南  男  30  7289.72"
      ]
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "mydf1.replace('赵可佳','王丽',inplace=True)\n",
    "mydf1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "218d5fa5",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>姓名</th>\n",
       "      <th>性别</th>\n",
       "      <th>年龄</th>\n",
       "      <th>工资</th>\n",
       "      <th>户籍地址</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>赵佳</td>\n",
       "      <td>女</td>\n",
       "      <td>25</td>\n",
       "      <td>5869.32</td>\n",
       "      <td>广州</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>张可</td>\n",
       "      <td>男</td>\n",
       "      <td>28</td>\n",
       "      <td>7256.34</td>\n",
       "      <td>深圳</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>周远</td>\n",
       "      <td>女</td>\n",
       "      <td>21</td>\n",
       "      <td>6895.89</td>\n",
       "      <td>北京</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>徐南</td>\n",
       "      <td>男</td>\n",
       "      <td>30</td>\n",
       "      <td>7289.72</td>\n",
       "      <td>上海</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   姓名 性别  年龄       工资 户籍地址\n",
       "0  赵佳  女  25  5869.32   广州\n",
       "1  张可  男  28  7256.34   深圳\n",
       "2  周远  女  21  6895.89   北京\n",
       "3  徐南  男  30  7289.72   上海"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import pandas as pd\n",
    "data={\"姓名\":[\"赵佳\",\"张可\",\"周远\",\"徐南\"],\n",
    "    \"性别\":['女','男','女','男'],\n",
    "    \"年龄\":[25,28,21,30],\n",
    "    \"工资\":[5869.32,7256.34,6895.89,7289.72],\n",
    "    '户籍地址':['广州','深圳','北京','上海']}\n",
    "mydf1 = pd.DataFrame(data)\n",
    "mydf1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "92bdb1ba",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>姓名</th>\n",
       "      <th>性别</th>\n",
       "      <th>年龄</th>\n",
       "      <th>工资</th>\n",
       "      <th>户籍地址</th>\n",
       "      <th>部门</th>\n",
       "      <th>工龄</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>赵佳</td>\n",
       "      <td>女</td>\n",
       "      <td>25.0</td>\n",
       "      <td>5869.32</td>\n",
       "      <td>广州</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>张可</td>\n",
       "      <td>男</td>\n",
       "      <td>28.0</td>\n",
       "      <td>7256.34</td>\n",
       "      <td>深圳</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>周远</td>\n",
       "      <td>女</td>\n",
       "      <td>21.0</td>\n",
       "      <td>6895.89</td>\n",
       "      <td>北京</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>徐南</td>\n",
       "      <td>男</td>\n",
       "      <td>30.0</td>\n",
       "      <td>7289.72</td>\n",
       "      <td>上海</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>技术部</td>\n",
       "      <td>4.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>销售部</td>\n",
       "      <td>7.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>人事部</td>\n",
       "      <td>2.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    姓名   性别    年龄       工资 户籍地址   部门   工龄\n",
       "0   赵佳    女  25.0  5869.32   广州  NaN  NaN\n",
       "1   张可    男  28.0  7256.34   深圳  NaN  NaN\n",
       "2   周远    女  21.0  6895.89   北京  NaN  NaN\n",
       "3   徐南    男  30.0  7289.72   上海  NaN  NaN\n",
       "0  NaN  NaN   NaN      NaN  NaN  技术部  4.0\n",
       "1  NaN  NaN   NaN      NaN  NaN  销售部  7.0\n",
       "2  NaN  NaN   NaN      NaN  NaN  人事部  2.0"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data1 = {'部门':[\"技术部\",\"销售部\",\"人事部\"],\n",
    "         '工龄':[4,7,2]}\n",
    "mydf2 = pd.DataFrame(data1)\n",
    "#display(mydf2)\n",
    "mydf3 = pd.concat([mydf1,mydf2])\n",
    "mydf3"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "faabdac6",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>姓名</th>\n",
       "      <th>性别</th>\n",
       "      <th>年龄</th>\n",
       "      <th>工资</th>\n",
       "      <th>户籍地址</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>赵佳</td>\n",
       "      <td>女</td>\n",
       "      <td>25</td>\n",
       "      <td>5869.32</td>\n",
       "      <td>广州</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>张可</td>\n",
       "      <td>男</td>\n",
       "      <td>28</td>\n",
       "      <td>7256.34</td>\n",
       "      <td>深圳</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>周远</td>\n",
       "      <td>女</td>\n",
       "      <td>21</td>\n",
       "      <td>6895.89</td>\n",
       "      <td>北京</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>徐南</td>\n",
       "      <td>男</td>\n",
       "      <td>30</td>\n",
       "      <td>7289.72</td>\n",
       "      <td>上海</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>赵佳</td>\n",
       "      <td>女</td>\n",
       "      <td>25</td>\n",
       "      <td>5869.32</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>张可</td>\n",
       "      <td>男</td>\n",
       "      <td>28</td>\n",
       "      <td>7256.34</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>周远</td>\n",
       "      <td>女</td>\n",
       "      <td>21</td>\n",
       "      <td>6895.89</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   姓名 性别  年龄       工资 户籍地址\n",
       "0  赵佳  女  25  5869.32   广州\n",
       "1  张可  男  28  7256.34   深圳\n",
       "2  周远  女  21  6895.89   北京\n",
       "3  徐南  男  30  7289.72   上海\n",
       "4  赵佳  女  25  5869.32  NaN\n",
       "5  张可  男  28  7256.34  NaN\n",
       "6  周远  女  21  6895.89  NaN"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import pandas as pd\n",
    "data1={\"姓名\":[\"赵佳\",\"张可\",\"周远\"],\n",
    "    \"性别\":['女','男','女'],\n",
    "    \"年龄\":[25,28,21],\n",
    "    \"工资\":[5869.32,7256.34,6895.89]}\n",
    "mydf2 = pd.DataFrame(data1)\n",
    "mydf3 = pd.concat([mydf1,mydf2],ignore_index=True)\n",
    "mydf3"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "a592abc4",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>姓名</th>\n",
       "      <th>性别</th>\n",
       "      <th>年龄</th>\n",
       "      <th>工资</th>\n",
       "      <th>户籍地址</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>赵佳</td>\n",
       "      <td>女</td>\n",
       "      <td>25.0</td>\n",
       "      <td>5869.32</td>\n",
       "      <td>广州</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>张可</td>\n",
       "      <td>男</td>\n",
       "      <td>28.0</td>\n",
       "      <td>7256.34</td>\n",
       "      <td>深圳</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>周远</td>\n",
       "      <td>女</td>\n",
       "      <td>21.0</td>\n",
       "      <td>6895.89</td>\n",
       "      <td>北京</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>徐南</td>\n",
       "      <td>男</td>\n",
       "      <td>30.0</td>\n",
       "      <td>7289.72</td>\n",
       "      <td>上海</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>赵佳</td>\n",
       "      <td>女</td>\n",
       "      <td>25.0</td>\n",
       "      <td>5869.32</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>张可</td>\n",
       "      <td>男</td>\n",
       "      <td>28.0</td>\n",
       "      <td>7256.34</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>周远</td>\n",
       "      <td>女</td>\n",
       "      <td>21.0</td>\n",
       "      <td>6895.89</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>李红</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>6789.30</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>赵闲</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>8796.50</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>刘峰</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>8800.32</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   姓名   性别    年龄       工资 户籍地址\n",
       "0  赵佳    女  25.0  5869.32   广州\n",
       "1  张可    男  28.0  7256.34   深圳\n",
       "2  周远    女  21.0  6895.89   北京\n",
       "3  徐南    男  30.0  7289.72   上海\n",
       "4  赵佳    女  25.0  5869.32  NaN\n",
       "5  张可    男  28.0  7256.34  NaN\n",
       "6  周远    女  21.0  6895.89  NaN\n",
       "7  李红  NaN   NaN  6789.30  NaN\n",
       "8  赵闲  NaN   NaN  8796.50  NaN\n",
       "9  刘峰  NaN   NaN  8800.32  NaN"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import pandas as pd\n",
    "data2 = {\"姓名\":[\"李红\",\"赵闲\",\"刘峰\"],\n",
    "        \"工资\":[6789.3,8796.5,8800.32]}\n",
    "mydf4 = pd.DataFrame(data2)\n",
    "mydf5 = pd.concat([mydf3,mydf4],ignore_index=True)\n",
    "mydf5"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "id": "bc668b5a",
   "metadata": {},
   "outputs": [
    {
     "ename": "TypeError",
     "evalue": "merge() got an unexpected keyword argument 'join'",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mTypeError\u001b[0m                                 Traceback (most recent call last)",
      "Cell \u001b[1;32mIn[46], line 4\u001b[0m\n\u001b[0;32m      2\u001b[0m mys1 \u001b[38;5;241m=\u001b[39m pd\u001b[38;5;241m.\u001b[39mSeries([\u001b[38;5;124m'\u001b[39m\u001b[38;5;124m李海\u001b[39m\u001b[38;5;124m'\u001b[39m,\u001b[38;5;124m'\u001b[39m\u001b[38;5;124m男\u001b[39m\u001b[38;5;124m'\u001b[39m,\u001b[38;5;241m32\u001b[39m,\u001b[38;5;241m5678.78\u001b[39m],index\u001b[38;5;241m=\u001b[39m[\u001b[38;5;124m'\u001b[39m\u001b[38;5;124m姓名\u001b[39m\u001b[38;5;124m'\u001b[39m,\u001b[38;5;124m'\u001b[39m\u001b[38;5;124m性别\u001b[39m\u001b[38;5;124m'\u001b[39m,\u001b[38;5;124m'\u001b[39m\u001b[38;5;124m年龄\u001b[39m\u001b[38;5;124m'\u001b[39m,\u001b[38;5;124m'\u001b[39m\u001b[38;5;124m工资\u001b[39m\u001b[38;5;124m'\u001b[39m])\n\u001b[0;32m      3\u001b[0m mys2 \u001b[38;5;241m=\u001b[39m pd\u001b[38;5;241m.\u001b[39mSeries([\u001b[38;5;124m'\u001b[39m\u001b[38;5;124m刘瑞\u001b[39m\u001b[38;5;124m'\u001b[39m,\u001b[38;5;124m'\u001b[39m\u001b[38;5;124m女\u001b[39m\u001b[38;5;124m'\u001b[39m,\u001b[38;5;241m24\u001b[39m,\u001b[38;5;241m4614.41\u001b[39m],index\u001b[38;5;241m=\u001b[39m[\u001b[38;5;124m'\u001b[39m\u001b[38;5;124m姓名\u001b[39m\u001b[38;5;124m'\u001b[39m,\u001b[38;5;124m'\u001b[39m\u001b[38;5;124m性别\u001b[39m\u001b[38;5;124m'\u001b[39m,\u001b[38;5;124m'\u001b[39m\u001b[38;5;124m年龄\u001b[39m\u001b[38;5;124m'\u001b[39m,\u001b[38;5;124m'\u001b[39m\u001b[38;5;124m工资\u001b[39m\u001b[38;5;124m'\u001b[39m])\n\u001b[1;32m----> 4\u001b[0m mydf6 \u001b[38;5;241m=\u001b[39m \u001b[43mpd\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mmerge\u001b[49m\u001b[43m(\u001b[49m\u001b[43m[\u001b[49m\u001b[43mmydf5\u001b[49m\u001b[43m,\u001b[49m\u001b[43mmys1\u001b[49m\u001b[43m,\u001b[49m\u001b[43mmys2\u001b[49m\u001b[43m]\u001b[49m\u001b[43m,\u001b[49m\u001b[43mjoin\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43mleft\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43maxis\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;241;43m1\u001b[39;49m\u001b[43m)\u001b[49m\n\u001b[0;32m      5\u001b[0m mydf6\n",
      "\u001b[1;31mTypeError\u001b[0m: merge() got an unexpected keyword argument 'join'"
     ]
    }
   ],
   "source": [
    "import pandas as pd\n",
    "mys1 = pd.Series(['李海','男',32,5678.78],index=['姓名','性别','年龄','工资'])\n",
    "mys2 = pd.Series(['刘瑞','女',24,4614.41],index=['姓名','性别','年龄','工资'])\n",
    "mydf6 = pd.merge([mydf5,mys1,mys2],join='left',axis=1)\n",
    "mydf6"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "209f4202",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>姓名</th>\n",
       "      <th>性别</th>\n",
       "      <th>年龄</th>\n",
       "      <th>工资</th>\n",
       "      <th>户籍地址</th>\n",
       "      <th>部门</th>\n",
       "      <th>工龄</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>赵佳</td>\n",
       "      <td>女</td>\n",
       "      <td>25.0</td>\n",
       "      <td>5869.32</td>\n",
       "      <td>广州</td>\n",
       "      <td>技术部</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>张可</td>\n",
       "      <td>男</td>\n",
       "      <td>28.0</td>\n",
       "      <td>7256.34</td>\n",
       "      <td>深圳</td>\n",
       "      <td>销售部</td>\n",
       "      <td>7</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>周远</td>\n",
       "      <td>女</td>\n",
       "      <td>21.0</td>\n",
       "      <td>6895.89</td>\n",
       "      <td>北京</td>\n",
       "      <td>人事部</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   姓名 性别    年龄       工资 户籍地址   部门  工龄\n",
       "0  赵佳  女  25.0  5869.32   广州  技术部   4\n",
       "1  张可  男  28.0  7256.34   深圳  销售部   7\n",
       "2  周远  女  21.0  6895.89   北京  人事部   2"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import pandas as pd\n",
    "mydata = {\"部门\":[\"技术部\",\"销售部\",\"人事部\"],\n",
    "         \"工龄\":[4,7,2]}\n",
    "mydf8 = pd.DataFrame(mydata)\n",
    "mydf9 = pd.concat([mydf5,mydf8],axis=1,join='inner')\n",
    "mydf9"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "35e5c21d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>编号</th>\n",
       "      <th>日期</th>\n",
       "      <th>姓名</th>\n",
       "      <th>性别</th>\n",
       "      <th>年龄</th>\n",
       "      <th>工资</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>100001</td>\n",
       "      <td>2021-11-08</td>\n",
       "      <td>赵佳</td>\n",
       "      <td>女</td>\n",
       "      <td>25</td>\n",
       "      <td>5869.32</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>100012</td>\n",
       "      <td>2021-11-09</td>\n",
       "      <td>张可</td>\n",
       "      <td>男</td>\n",
       "      <td>28</td>\n",
       "      <td>7256.34</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>100003</td>\n",
       "      <td>2021-11-10</td>\n",
       "      <td>周远</td>\n",
       "      <td>女</td>\n",
       "      <td>21</td>\n",
       "      <td>6895.89</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>100004</td>\n",
       "      <td>2021-11-11</td>\n",
       "      <td>徐南</td>\n",
       "      <td>男</td>\n",
       "      <td>30</td>\n",
       "      <td>7289.72</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "       编号         日期  姓名 性别  年龄       工资\n",
       "0  100001 2021-11-08  赵佳  女  25  5869.32\n",
       "1  100012 2021-11-09  张可  男  28  7256.34\n",
       "2  100003 2021-11-10  周远  女  21  6895.89\n",
       "3  100004 2021-11-11  徐南  男  30  7289.72"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>编号</th>\n",
       "      <th>部门</th>\n",
       "      <th>工龄</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>100001</td>\n",
       "      <td>技术部</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>10002</td>\n",
       "      <td>销售部</td>\n",
       "      <td>7</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>100053</td>\n",
       "      <td>人事部</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "       编号   部门  工龄\n",
       "0  100001  技术部   4\n",
       "1   10002  销售部   7\n",
       "2  100053  人事部   2"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "import pandas as pd\n",
    "import numpy as np\n",
    "data = {  \"编号\":[100001,100012,100003,100004],\n",
    "          \"日期\":pd.date_range('20211108', periods=4),\n",
    "          \"姓名\":[\"赵佳\",\"张可\",\"周远\",\"徐南\"],\n",
    "          \"性别\":['女','男','女','男'],\n",
    "          \"年龄\":[25,28,21,30],\n",
    "          \"工资\":[5869.32,7256.34,6895.89,7289.72]\n",
    "       }\n",
    "mydf1 = pd.DataFrame(data) \n",
    "display(mydf1)\n",
    "data1 = {  \"编号\":[100001,10002,100053],\n",
    "          \"部门\":[\"技术部\",\"销售部\",\"人事部\"],\n",
    "          \"工龄\":[4,7,2]\n",
    "       }\n",
    "mydf2 = pd.DataFrame(data1)\n",
    "display(mydf2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "aba32321",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>编号</th>\n",
       "      <th>日期</th>\n",
       "      <th>姓名</th>\n",
       "      <th>性别</th>\n",
       "      <th>年龄</th>\n",
       "      <th>工资</th>\n",
       "      <th>部门</th>\n",
       "      <th>工龄</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>100001</td>\n",
       "      <td>2021-11-08</td>\n",
       "      <td>赵佳</td>\n",
       "      <td>女</td>\n",
       "      <td>25</td>\n",
       "      <td>5869.32</td>\n",
       "      <td>技术部</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "       编号         日期  姓名 性别  年龄       工资   部门  工龄\n",
       "0  100001 2021-11-08  赵佳  女  25  5869.32  技术部   4"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "df_inner = pd.merge(mydf1,mydf2,how='inner')\n",
    "display(df_inner)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "d7e46e14",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>编号</th>\n",
       "      <th>日期</th>\n",
       "      <th>姓名</th>\n",
       "      <th>性别</th>\n",
       "      <th>年龄</th>\n",
       "      <th>工资</th>\n",
       "      <th>部门</th>\n",
       "      <th>工龄</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>100001</td>\n",
       "      <td>2021-11-08</td>\n",
       "      <td>赵佳</td>\n",
       "      <td>女</td>\n",
       "      <td>25</td>\n",
       "      <td>5869.32</td>\n",
       "      <td>技术部</td>\n",
       "      <td>4.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>100012</td>\n",
       "      <td>2021-11-09</td>\n",
       "      <td>张可</td>\n",
       "      <td>男</td>\n",
       "      <td>28</td>\n",
       "      <td>7256.34</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>100003</td>\n",
       "      <td>2021-11-10</td>\n",
       "      <td>周远</td>\n",
       "      <td>女</td>\n",
       "      <td>21</td>\n",
       "      <td>6895.89</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>100004</td>\n",
       "      <td>2021-11-11</td>\n",
       "      <td>徐南</td>\n",
       "      <td>男</td>\n",
       "      <td>30</td>\n",
       "      <td>7289.72</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "       编号         日期  姓名 性别  年龄       工资   部门   工龄\n",
       "0  100001 2021-11-08  赵佳  女  25  5869.32  技术部  4.0\n",
       "1  100012 2021-11-09  张可  男  28  7256.34  NaN  NaN\n",
       "2  100003 2021-11-10  周远  女  21  6895.89  NaN  NaN\n",
       "3  100004 2021-11-11  徐南  男  30  7289.72  NaN  NaN"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "# 左连接\n",
    "df_left = pd.merge(mydf1,mydf2,how='left')\n",
    "display(df_left)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "id": "660ffcab",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>编号</th>\n",
       "      <th>日期</th>\n",
       "      <th>姓名</th>\n",
       "      <th>性别</th>\n",
       "      <th>年龄</th>\n",
       "      <th>工资</th>\n",
       "      <th>部门</th>\n",
       "      <th>工龄</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>100001</td>\n",
       "      <td>2021-11-08</td>\n",
       "      <td>赵佳</td>\n",
       "      <td>女</td>\n",
       "      <td>25.0</td>\n",
       "      <td>5869.32</td>\n",
       "      <td>技术部</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>10002</td>\n",
       "      <td>NaT</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>销售部</td>\n",
       "      <td>7</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>100053</td>\n",
       "      <td>NaT</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>人事部</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "       编号         日期   姓名   性别    年龄       工资   部门  工龄\n",
       "0  100001 2021-11-08   赵佳    女  25.0  5869.32  技术部   4\n",
       "1   10002        NaT  NaN  NaN   NaN      NaN  销售部   7\n",
       "2  100053        NaT  NaN  NaN   NaN      NaN  人事部   2"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "# 右连接\n",
    "df_right = pd.merge(mydf1,mydf2,how='right')\n",
    "display(df_right)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "id": "1a8c4f26",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>编号</th>\n",
       "      <th>日期</th>\n",
       "      <th>姓名</th>\n",
       "      <th>性别</th>\n",
       "      <th>年龄</th>\n",
       "      <th>工资</th>\n",
       "      <th>部门</th>\n",
       "      <th>工龄</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>10002</td>\n",
       "      <td>NaT</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>销售部</td>\n",
       "      <td>7.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>100001</td>\n",
       "      <td>2021-11-08</td>\n",
       "      <td>赵佳</td>\n",
       "      <td>女</td>\n",
       "      <td>25.0</td>\n",
       "      <td>5869.32</td>\n",
       "      <td>技术部</td>\n",
       "      <td>4.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>100003</td>\n",
       "      <td>2021-11-10</td>\n",
       "      <td>周远</td>\n",
       "      <td>女</td>\n",
       "      <td>21.0</td>\n",
       "      <td>6895.89</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>100004</td>\n",
       "      <td>2021-11-11</td>\n",
       "      <td>徐南</td>\n",
       "      <td>男</td>\n",
       "      <td>30.0</td>\n",
       "      <td>7289.72</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>100012</td>\n",
       "      <td>2021-11-09</td>\n",
       "      <td>张可</td>\n",
       "      <td>男</td>\n",
       "      <td>28.0</td>\n",
       "      <td>7256.34</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>100053</td>\n",
       "      <td>NaT</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>人事部</td>\n",
       "      <td>2.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "       编号         日期   姓名   性别    年龄       工资   部门   工龄\n",
       "0   10002        NaT  NaN  NaN   NaN      NaN  销售部  7.0\n",
       "1  100001 2021-11-08   赵佳    女  25.0  5869.32  技术部  4.0\n",
       "2  100003 2021-11-10   周远    女  21.0  6895.89  NaN  NaN\n",
       "3  100004 2021-11-11   徐南    男  30.0  7289.72  NaN  NaN\n",
       "4  100012 2021-11-09   张可    男  28.0  7256.34  NaN  NaN\n",
       "5  100053        NaT  NaN  NaN   NaN      NaN  人事部  2.0"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "# 全外连接\n",
    "df_outer = pd.merge(mydf1,mydf2,how='outer')\n",
    "display(df_outer)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "id": "e28123b1",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>编号</th>\n",
       "      <th>日期</th>\n",
       "      <th>姓名</th>\n",
       "      <th>性别</th>\n",
       "      <th>年龄</th>\n",
       "      <th>工资</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>100001</td>\n",
       "      <td>2021-11-08</td>\n",
       "      <td>赵佳</td>\n",
       "      <td>女</td>\n",
       "      <td>25</td>\n",
       "      <td>5869.32</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>100012</td>\n",
       "      <td>2021-11-09</td>\n",
       "      <td>张可</td>\n",
       "      <td>男</td>\n",
       "      <td>28</td>\n",
       "      <td>7256.34</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>100003</td>\n",
       "      <td>2021-11-10</td>\n",
       "      <td>周远</td>\n",
       "      <td>女</td>\n",
       "      <td>21</td>\n",
       "      <td>6895.89</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>100004</td>\n",
       "      <td>2021-11-11</td>\n",
       "      <td>徐南</td>\n",
       "      <td>男</td>\n",
       "      <td>30</td>\n",
       "      <td>7289.72</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "       编号         日期  姓名 性别  年龄       工资\n",
       "0  100001 2021-11-08  赵佳  女  25  5869.32\n",
       "1  100012 2021-11-09  张可  男  28  7256.34\n",
       "2  100003 2021-11-10  周远  女  21  6895.89\n",
       "3  100004 2021-11-11  徐南  男  30  7289.72"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>编号</th>\n",
       "      <th>日期</th>\n",
       "      <th>姓名</th>\n",
       "      <th>性别</th>\n",
       "      <th>年龄</th>\n",
       "      <th>工资</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>100001</td>\n",
       "      <td>2021-11-08</td>\n",
       "      <td>王心龙</td>\n",
       "      <td>女</td>\n",
       "      <td>25</td>\n",
       "      <td>5869.32</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>100012</td>\n",
       "      <td>2021-11-09</td>\n",
       "      <td>张可</td>\n",
       "      <td>男</td>\n",
       "      <td>42</td>\n",
       "      <td>7256.34</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>100003</td>\n",
       "      <td>2021-11-10</td>\n",
       "      <td>周远</td>\n",
       "      <td>女</td>\n",
       "      <td>21</td>\n",
       "      <td>6895.89</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>100004</td>\n",
       "      <td>2021-11-11</td>\n",
       "      <td>徐南</td>\n",
       "      <td>男</td>\n",
       "      <td>30</td>\n",
       "      <td>4611.11</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "       编号         日期   姓名 性别  年龄       工资\n",
       "0  100001 2021-11-08  王心龙  女  25  5869.32\n",
       "1  100012 2021-11-09   张可  男  42  7256.34\n",
       "2  100003 2021-11-10   周远  女  21  6895.89\n",
       "3  100004 2021-11-11   徐南  男  30  4611.11"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "import pandas as pd\n",
    "import numpy as np\n",
    "data = {  \"编号\":[100001,100012,100003,100004],\n",
    "          \"日期\":pd.date_range('20211108', periods=4),\n",
    "          \"姓名\":[\"赵佳\",\"张可\",\"周远\",\"徐南\"],\n",
    "          \"性别\":['女','男','女','男'],\n",
    "          \"年龄\":[25,28,21,30],\n",
    "          \"工资\":[5869.32,7256.34,6895.89,7289.72]\n",
    "       }\n",
    "mydf1 = pd.DataFrame(data) \n",
    "display(mydf1)\n",
    "\n",
    "mydf2 = mydf1.copy()\n",
    "mydf2.loc[0, '姓名'] = '王心龙'\n",
    "mydf2.loc[1, '年龄'] = 42\n",
    "mydf2.loc[3, '工资'] = 4611.11\n",
    "display(mydf2)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "id": "5b5c5036",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th>编号</th>\n",
       "      <th>日期</th>\n",
       "      <th>姓名</th>\n",
       "      <th>性别</th>\n",
       "      <th>年龄</th>\n",
       "      <th>工资</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th rowspan=\"2\" valign=\"top\">0</th>\n",
       "      <th>self</th>\n",
       "      <td>100001</td>\n",
       "      <td>2021-11-08</td>\n",
       "      <td>赵佳</td>\n",
       "      <td>女</td>\n",
       "      <td>25</td>\n",
       "      <td>5869.32</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>other</th>\n",
       "      <td>100001</td>\n",
       "      <td>2021-11-08</td>\n",
       "      <td>王心龙</td>\n",
       "      <td>女</td>\n",
       "      <td>25</td>\n",
       "      <td>5869.32</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th rowspan=\"2\" valign=\"top\">1</th>\n",
       "      <th>self</th>\n",
       "      <td>100012</td>\n",
       "      <td>2021-11-09</td>\n",
       "      <td>张可</td>\n",
       "      <td>男</td>\n",
       "      <td>28</td>\n",
       "      <td>7256.34</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>other</th>\n",
       "      <td>100012</td>\n",
       "      <td>2021-11-09</td>\n",
       "      <td>张可</td>\n",
       "      <td>男</td>\n",
       "      <td>42</td>\n",
       "      <td>7256.34</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th rowspan=\"2\" valign=\"top\">2</th>\n",
       "      <th>self</th>\n",
       "      <td>100003</td>\n",
       "      <td>2021-11-10</td>\n",
       "      <td>周远</td>\n",
       "      <td>女</td>\n",
       "      <td>21</td>\n",
       "      <td>6895.89</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>other</th>\n",
       "      <td>100003</td>\n",
       "      <td>2021-11-10</td>\n",
       "      <td>周远</td>\n",
       "      <td>女</td>\n",
       "      <td>21</td>\n",
       "      <td>6895.89</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th rowspan=\"2\" valign=\"top\">3</th>\n",
       "      <th>self</th>\n",
       "      <td>100004</td>\n",
       "      <td>2021-11-11</td>\n",
       "      <td>徐南</td>\n",
       "      <td>男</td>\n",
       "      <td>30</td>\n",
       "      <td>7289.72</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>other</th>\n",
       "      <td>100004</td>\n",
       "      <td>2021-11-11</td>\n",
       "      <td>徐南</td>\n",
       "      <td>男</td>\n",
       "      <td>30</td>\n",
       "      <td>4611.11</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "             编号         日期   姓名 性别  年龄       工资\n",
       "0 self   100001 2021-11-08   赵佳  女  25  5869.32\n",
       "  other  100001 2021-11-08  王心龙  女  25  5869.32\n",
       "1 self   100012 2021-11-09   张可  男  28  7256.34\n",
       "  other  100012 2021-11-09   张可  男  42  7256.34\n",
       "2 self   100003 2021-11-10   周远  女  21  6895.89\n",
       "  other  100003 2021-11-10   周远  女  21  6895.89\n",
       "3 self   100004 2021-11-11   徐南  男  30  7289.72\n",
       "  other  100004 2021-11-11   徐南  男  30  4611.11"
      ]
     },
     "execution_count": 33,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "mydf1.compare(mydf2,align_axis=0,keep_equal=True,keep_shape=True)\n",
    "#mydf1.compare(mydf2,align_axis=1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "14412f61",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.1"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
